package com.css.fxfzcpxx.modules.infoRetrieval.historicalSeismicInfo.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzcpxx.base.log.Log;
import com.css.fxfzcpxx.base.response.RestResponse;
import com.css.fxfzcpxx.modules.earthquakeDisaster.entity.EarthquakeDisaster;
import com.css.fxfzcpxx.modules.earthquakeDisaster.vo.EarthquakeDisasterVO;
import com.css.fxfzcpxx.modules.infoRetrieval.historicalSeismicInfo.param.FindByParam;
import com.css.fxfzcpxx.modules.infoRetrieval.historicalSeismicInfo.param.HistoricalSeismicEventParam;
import com.css.fxfzcpxx.modules.infoRetrieval.historicalSeismicInfo.entity.MapData;
import com.css.fxfzcpxx.modules.infoRetrieval.historicalSeismicInfo.service.HistoricalSeismicEventService;
import com.css.fxfzcpxx.util.PlatformPageUtils;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Author: zhangSongRui
 * @CreateTime: 2023/04/07
 * @Description: 历史地震事件
 */
@Api(tags ="历史地震事件")
@Slf4j
@RestController
@RequestMapping("/historicalSeismicEvent")
public class HistoricalSeismicEventController {
    @Resource
    private HistoricalSeismicEventService historicalSeismicEventService;

    /**
     * 查询三年内4级以上的地震
     * @return
     */
    @GetMapping("/queryAllByParam")
    @Operation(summary = "查询三年内4级以上的地震")
    public RestResponse queryAllByParam() {
        try {
            List<MapData> data = historicalSeismicEventService.queryAllByParam();
            return RestResponse.succeed(data);
        } catch (Exception e) {
            log.error("失败!", e);
            return RestResponse.fail("失败!");
        }
    }

    /**
     * 分页列表
     * @param param 参数
     * @return page
     */
    @GetMapping("/getPage")
    @Log(value="信息检索",type = "检索")
    public RestResponse getPage(HttpServletRequest request, HistoricalSeismicEventParam param) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            int curPage =Integer.parseInt(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize =Integer.parseInt(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            Map<String, Object> page = historicalSeismicEventService.getPage(curPage, pageSize,param);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(page);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
    /**
     * 查询详情
     * @param param 参数
     * @return
     */
    @GetMapping("/findByParam")
    public RestResponse findByParam(FindByParam param) {
        RestResponse restResponse = null;
        try {
            EarthquakeDisasterVO byParam = historicalSeismicEventService.findByParam(param);
            restResponse = RestResponse.succeed(byParam);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 查询详情
     * @param id
     * @return
     */
    @GetMapping("/findById")
    @Operation(summary = "根据id查询")
    public RestResponse findById(String id) {
        RestResponse restResponse = null;
        try {
            Map<String, Object> byParam = historicalSeismicEventService.findById(id);
            restResponse = RestResponse.succeed(byParam);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
}
